import { ApiProperty, IntersectionType, PartialType } from '@nestjs/swagger';
import {
  ArrayMaxSize,
  ArrayMinSize,
  ArrayNotEmpty,
  IsIn,
  IsInt,
  IsNumber,
  IsOptional,
  IsString,
  Matches,
  MaxLength,
  MinLength,
} from 'class-validator';

import { PagerDto } from '~/common/dto/pager.dto';

export class UserDto {
  @ApiProperty({ description: '登录账号', example: 'admin' })
  @IsString()
  @Matches(/^[a-z0-9A-Z\W_]+$/)
  @MinLength(4)
  @MaxLength(20)
  username: string;

  @ApiProperty({ description: '登录密码', example: 'a123456' })
  @IsOptional()
  @Matches(/^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Za-z])\S*$/, {
    message: '密码必须包含数字、字母，长度为6-16',
  })
  password: string;

  @ApiProperty({ description: '归属角色', default: 1 })
  @IsNumber()
  role: number;

  @ApiProperty({ description: '备注', default: '' })
  @IsOptional()
  @IsString()
  remark?: string;

  @ApiProperty({ description: '状态', default: 1 })
  @IsIn([0, 1])
  status: number;

	@ApiProperty({ description: '租户ID', default: null })
	@IsInt()
	@IsOptional()
	tenantId: number;
}

export class UserUpdateDto extends PartialType(UserDto) {}

export class UserQueryDto extends IntersectionType(PagerDto<UserDto>, PartialType(UserDto)) {
  @ApiProperty({ description: '归属大区', example: 1, required: false })
  @IsInt()
  @IsOptional()
  deptId?: number;

  @ApiProperty({ description: '状态', example: 0, required: false })
  @IsInt()
  @IsOptional()
  status?: number;
}

export class UserNormalQueryDto extends PagerDto {
  @ApiProperty({ description: '昵称', example: '张三', required: false })
  @IsString()
  @IsOptional()
  nickname?: string;

  @ApiProperty({ description: '手机号', example: '13800138000', required: false })
  @IsString()
  @IsOptional()
  phone?: string;

  @ApiProperty({ description: '租户ID', example: 1, required: false })
  @IsInt()
  @IsOptional()
  tenantId?: number;
}


